﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;

namespace MediaRegister
{
    public partial class FormSäljData : Form
    {
        private struct säljData
        {
            public string Nr;
            public string Modell;
            public string SerieNr;
            public string Specifikation;
        }
        public FormSäljData()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            säljData säljd;
            säljd.Nr = textBox1.Text;
            säljd.Modell = textBox2.Text;
            säljd.SerieNr = textBox3.Text;
            säljd.Specifikation = textBox4.Text;
            FileStream fs1 = new FileStream(@"M:\SäljData.txt", FileMode.Append, FileAccess.Write);
            StreamWriter sr1 = new StreamWriter(fs1);
            sr1.WriteLine(säljd.Nr + " , " + säljd.Modell + " , " + säljd.SerieNr + " , " + säljd.Specifikation);
            foreach (Control t in this.Controls)
                if (t is TextBox)
                    t.Text = " ";
            sr1.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
            String s1;
            if (File.Exists(@"M:\SäljData.txt"))
            {
                FileStream fs1 = new FileStream(@"M:\SäljData.txt", FileMode.Open, FileAccess.Read);
                StreamReader sr1 = new StreamReader(fs1);
                s1 = sr1.ReadLine();
                while (s1 != null)
                {
                    listBox1.Items.Add(s1);
                    s1 = sr1.ReadLine();

                }
                sr1.Close();
            }

            else
            {
                MessageBox.Show("Finns ingen fil att visa");
            }
        }

       
      

    }
}
